package com.tsunami.exception;

import com.tsunami.exception.code.ExceptionCode;
import io.swagger.v3.oas.annotations.media.Schema;

/**
 * 自定义异常
 *
 * @author lx
 * @date 2021-09-10 18:29
 */
public class BizException extends RuntimeException {
    @Schema(description = "错误信息")
    protected final String message;
    @Schema(description = "错误代码")
    protected final Integer code;

    public BizException(String message, Integer code) {
        this.message = message;
        this.code = code;
    }

    public BizException(ExceptionCode ex) {
        this.message = ex.getMsg();
        this.code = ex.getCode();
    }

    public BizException(String message, Integer code, Throwable e) {
        super(message, e);
        this.message = message;
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public Integer getCode() {
        return code;
    }
}
